do{ Statements ---------- } while(condition); next statements...
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.println("Enter numbers :"); int s=0, a; do{ a=stdin.nextInt( ); s=s+a; }while(a!=0); System.out.println("Sum is "+s); } }
Enter a number 5 2 3 6 0 Sum is 16
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.println("Enter numbers :"); int s=0,a; do{ a=stdin.nextInt(); if(a%2==0) s=s+a; }while(a!=0); System.out.println("Sum of even is "+s); } }
Enter a number 5 2 7 6 0 Sum of even is 8
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.println("Enter numbers :"); int s=0, a; do{ a=stdin.nextInt(); if(a>0) c=c+1; }while(a!=0); System.out.println(“Total positive nos is “+c); } }
Enter numbers: 7 -12 8 -10 5 4 1 0 Total positive numbers 5
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.println("Enter numbers :"); int c1=0, c2=0, a; do{ a=stdin.nextInt(); if(a>0) c1=c1+1; if(a⁢0) c2=c2+1; }while(a!=0); System.out.println("Total positive numbers are "+c1); System.out.println("Total negative numbers are "+c2); } }
Enter numbers: 7 -12 8 -10 5 4 1 0 Total positive numbers are 5 Total negative numbers are 2